package com.ygxsk.carhome.ui.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.FeePayTypeListBean;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-12-21  11:25
 * @Description:支付方式弹窗的适配器,主要是水费和电费的支付方式， 物业缴费，要不要统一用这个？
 */
public class FeePayTypePopuAdatper extends BaseQuickAdapter<FeePayTypeListBean, BaseViewHolder> {

    public FeePayTypePopuAdatper(int layoutResId, @Nullable List<FeePayTypeListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, FeePayTypeListBean feePayTypeListBean) {

//                "image": "http://222.222.17.184:19181/resource/shop/image/pay/0.png",
//                "isEnable": 1,
//                "isOnline": 1,
//                "payName": "支付宝支付",
//                "payRate": 0.0060,
//                "payTypeCode": "ALIPAY_APP",
//                "payTypeId": 1,
//                "sortCode": 1

        if (feePayTypeListBean != null) {

            //支付方式的图标
            String url = feePayTypeListBean.getImage();

            //支付方式的名称
            String name = feePayTypeListBean.getPayName();

            //支付id, "payTypeCode": "ALIPAY_APP",
            String payType = feePayTypeListBean.getPayTypeCode();

            //是否被选中
            boolean isChecked = feePayTypeListBean.isChecked();

            //支付图标
            ImageView imageViewPayIcon = (ImageView) baseViewHolder.getView(R.id.imageviewpayiconfee);

            //支付方式的文字信息
            TextView textViewPayName = (TextView) baseViewHolder.getView(R.id.textviewpaynamefee);

            //选中状态
            CheckBox checkBoxInPayFee = (CheckBox) baseViewHolder.getView(R.id.checkboxinpayewafee);

            //底部有一条横线
            //底部的一个线条
            TextView textViewAdapterBottomHelper = (TextView) baseViewHolder.getView(R.id.textViewAdapterBottomHelperFee);

            int indexPositon = getItemPosition(feePayTypeListBean);

            //最后一个展示
            if (indexPositon == getData().size() - 1) {
                textViewAdapterBottomHelper.setVisibility(View.VISIBLE);
            } else {
                textViewAdapterBottomHelper.setVisibility(View.GONE);
            }

            textViewPayName.setText(name);

            //设置图标
            Glide.with(getContext())//
                    .load(url)//
                    .placeholder(R.drawable.icon_errorfang)//
                    .error(R.drawable.icon_errorfang)//
                    .fallback(R.drawable.icon_errorfang)//
                    .into(imageViewPayIcon);//

            //选中的变换
            if (isChecked) {
                checkBoxInPayFee.setChecked(true);
            } else {
                checkBoxInPayFee.setChecked(false);
            }

        }

    }
}
